package com.cskaoyan.wx.service;

import com.cskaoyan.bean.Order;
import com.cskaoyan.bean.OrderExample;
import com.cskaoyan.bean.OrderGoods;
import com.cskaoyan.bean.OrderGoodsExample;
import com.cskaoyan.bo.WxOrderCommentBo;

import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.OrderMapper;

import com.cskaoyan.wx.bean.Comment;
import com.cskaoyan.wx.mapper.CommentMapper;
import com.cskaoyan.wx.vo.DetailVo;
import com.cskaoyan.wx.vo.ListShowTypeVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2021/4/12 - 17:10
 */
@Service
public class WxOrderServiceImpl implements WxOrderService {

    @Autowired
    CommentMapper commentMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;
    @Autowired
    OrderMapper orderMapper;

    @Override
    public int comment(WxOrderCommentBo wxOrderCommentBo) {

        Comment comment = new Comment();
        comment.setAddTime(new Date());
        comment.setUpdateTime(new Date());
        if (!wxOrderCommentBo.getHasPicture()) {
            comment.setPicUrls(null);
            comment.setHasPicture(false);
        }
        comment.setPicUrls(wxOrderCommentBo.getPicUrls());
        comment.setHasPicture(true);
        comment.setStar(wxOrderCommentBo.getStar());
        comment.setContent(wxOrderCommentBo.getContent());
        comment.setValueId(wxOrderCommentBo.getOrderGoodsId());
        comment.setDeleted(false);


        // 没明白是什么状态码
        comment.setType((byte) 0);

        // 测试了下参数ordergoodsid 是 order 的 id
        Integer id = wxOrderCommentBo.getOrderGoodsId();
        Order order = orderMapper.selectByPrimaryKey(id);
        comment.setUserId(order.getUserId());

        int insert = commentMapper.insert(comment);
        OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
        orderGoodsExample.createCriteria().andOrderIdEqualTo(id);
        List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);
        for (OrderGoods orderGoods : orderGoodsList) {
            Integer id1 = comment.getId();
            orderGoods.setComment(id1);
            int i = orderGoodsMapper.updateByPrimaryKeySelective(orderGoods);
            if(i<=0){
                return 0;
            }
            return 1;
        }

        if (insert <= 0) {
            return 0;
        }
        return 1;
    }

    @Override
    public void cancel(Integer orderId) {
        // 未完善系统取消订单
        Order order = orderMapper.selectByPrimaryKey(orderId);
        order.setOrderStatus((short) 102);
        orderMapper.updateByPrimaryKeySelective(order);

    }

    @Override
    public void delete(Integer orderId) {

        orderMapper.deleteByPrimaryKey(orderId);

        orderGoodsMapper.deleteByOrderId(orderId);
    }

    @Override
    public DetailVo detail(Integer orderId) {

        DetailVo.OrderInfoBean orderInfoBean = new DetailVo.OrderInfoBean();
        Order order = orderMapper.selectByPrimaryKey(orderId);
        OrderGoods orderGoods = orderGoodsMapper.selectByPrimaryKey(orderId);
        orderInfoBean.setConsignee(order.getConsignee());
        orderInfoBean.setAddress(order.getAddress());
        orderInfoBean.setAddTime(order.getAddTime());
        orderInfoBean.setActualPrice(order.getActualPrice());
        orderInfoBean.setOrderSn(order.getOrderSn());
        orderInfoBean.setMobile(order.getMobile());
        Short orderStatus = order.getOrderStatus();
        DetailVo.OrderInfoBean.HandleOptionBean handleOptionBean = new DetailVo.OrderInfoBean.HandleOptionBean();

        String status = null;
        if (orderStatus == 101) {
            status = "未付款";

        } else if (orderStatus == 102 || orderStatus == 103) {
            status = "已取消";

        } else if (orderStatus == 201) {
            status = "已付款";

        } else if (orderStatus == 202) {
            status = "订单取消，退款中";
            ;
        } else if (orderStatus == 203) {
            status = "已退款";

        } else if (orderStatus == 301) {
            status = "已发货";

        } else if (orderStatus == 401 || orderStatus == 402) {
            status = "已收货";

        }
        orderInfoBean.setOrderStatusText(status);
        orderInfoBean.setGoodsPrice(order.getGoodsPrice());
        orderInfoBean.setCouponPrice(0);
        orderInfoBean.setId(orderId);
        orderInfoBean.setFreightPrice(0);

        if (orderStatus == 101) {

            handleOptionBean.setCancel(true);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(false);
            handleOptionBean.setPay(true);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);

        } else if (orderStatus == 102) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(true);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);

        } else if (orderStatus == 103) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(true);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 201) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(false);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(true);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 202) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(false);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 203) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(true);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(true);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 301) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(false);
            handleOptionBean.setConfirm(true);
            handleOptionBean.setDelete(false);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(false);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 401) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(true);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(true);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(true);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        } else if (orderStatus == 402) {

            handleOptionBean.setCancel(false);
            handleOptionBean.setComment(true);
            handleOptionBean.setConfirm(false);
            handleOptionBean.setDelete(true);
            handleOptionBean.setPay(false);
            handleOptionBean.setRebuy(true);
            handleOptionBean.setRefund(false);
            orderInfoBean.setHandleOption(handleOptionBean);
        }
        ArrayList<DetailVo.OrderGoodsBean> orderGoodsBeans = new ArrayList<>();


        //根据orderid找多goods
        //也有问题

        DetailVo.OrderGoodsBean orderGoodsBean = new DetailVo.OrderGoodsBean();
        orderGoodsBean.setId(orderId);
        orderGoodsBean.setOrderId(orderId);
        orderGoodsBean.setGoodsId(orderGoods.getGoodsId());
        orderGoodsBean.setGoodsName(orderGoods.getGoodsName());
        orderGoodsBean.setGoodsSn(orderGoods.getGoodsSn());
        orderGoodsBean.setProductId(orderGoods.getProductId());
        orderGoodsBean.setNumber(orderGoods.getNumber());
        orderGoodsBean.setPrice(orderGoods.getPrice());
        orderGoodsBean.setSpecifications(orderGoods.getSpecifications());
        orderGoodsBean.setPicUrl(orderGoods.getPicUrl());

        // 这个应该有问题
        orderGoodsBean.setComment(orderGoods.getComment());
        orderGoodsBean.setAddTime(orderGoods.getAddTime());
        orderGoodsBean.setUpdateTime(orderGoods.getUpdateTime());
        orderGoodsBean.setDeleted(false);

        orderGoodsBeans.add(orderGoodsBean);


        DetailVo detailVo = new DetailVo();
        detailVo.setOrderGoods(orderGoodsBeans);
        detailVo.setOrderInfo(orderInfoBean);

        return detailVo;


    }


    @Override
    public ListShowTypeVo list(Integer showType, Integer page, Integer size) {

        // 分页
        PageHelper.startPage(page, size);
        OrderExample orderExample = new OrderExample();
        ListShowTypeVo listShowTypeVo = new ListShowTypeVo();


        ListShowTypeVo.DataBean.HandleOptionBean handleOptionBean = new ListShowTypeVo.DataBean.HandleOptionBean();
        ArrayList<ListShowTypeVo.DataBean> dataBeans = new ArrayList<>();


        if (showType == 0) {
            long count = orderMapper.countByExample(orderExample);
            listShowTypeVo.setCount((int) count);
            int ceil = (int) Math.ceil((count / size));
            if (ceil > 0) {
                page = ceil + 1;
            } else {
                page = 0;
            }
            listShowTypeVo.setTotalPages(page);
            List<Order> orders = orderMapper.selectByExample(orderExample);


            for (Order order : orders) {
                ListShowTypeVo.DataBean dataBean = new ListShowTypeVo.DataBean();
                if (order.getOrderStatus() == 101) {
                    dataBean.setOrderStatusText("未付款");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(true);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(true);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);


                } else if (order.getOrderStatus() == 102) {

                    dataBean.setOrderStatusText("用户取消");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);

                } else if (order.getOrderStatus() == 103) {
                    dataBean.setOrderStatusText("系统取消");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 201) {
                    dataBean.setOrderStatusText("已付款");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(true);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 202) {
                    dataBean.setOrderStatusText("订单取消，退款中");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 203) {
                    dataBean.setOrderStatusText("已退款");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(true);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 301) {
                    dataBean.setOrderStatusText("已发货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(true);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 401) {
                    dataBean.setOrderStatusText("用户收货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(true);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(true);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                } else if (order.getOrderStatus() == 402) {
                    dataBean.setOrderStatusText("系统收货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(true);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(true);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                }


                Integer orderId = order.getId();
                OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
                orderGoodsExample.createCriteria().andOrderIdEqualTo(orderId);
                List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);

                ArrayList<ListShowTypeVo.DataBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (OrderGoods orderGoods : orderGoodsList) {

                    ListShowTypeVo.DataBean.GoodsListBean goodsListBean = new ListShowTypeVo.DataBean.GoodsListBean();

                    goodsListBean.setId(orderGoods.getId());
                    goodsListBean.setGoodsName(orderGoods.getGoodsName());
                    goodsListBean.setPicUrl(orderGoods.getPicUrl());
                    goodsListBean.setNumber(orderGoods.getNumber());
                    goodsListBeans.add(goodsListBean);
                    dataBean.setGoodsList(goodsListBeans);

                    dataBeans.add(dataBean);

                }

            }
            listShowTypeVo.setData(dataBeans);
            return listShowTypeVo;

        }


        if (showType == 1) {

            orderExample.createCriteria().andOrderStatusEqualTo((short) 101);
            long count = orderMapper.countByExample(orderExample);
            listShowTypeVo.setCount((int) count);
            int ceil = (int) Math.ceil(count / size);
            if (ceil > 0) {
                page = size + 1;
            } else {
                page = 0;
            }
            listShowTypeVo.setTotalPages(page);
            List<Order> orders = orderMapper.selectByExample(orderExample);


            for (Order order : orders) {
                ListShowTypeVo.DataBean dataBean = new ListShowTypeVo.DataBean();
                if (order.getOrderStatus() == 101) {
                    dataBean.setOrderStatusText("未付款");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(true);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(true);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);
                }

                Integer orderId = order.getId();
                OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
                orderGoodsExample.createCriteria().andOrderIdEqualTo(orderId);
                List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);

                ArrayList<ListShowTypeVo.DataBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (OrderGoods orderGoods : orderGoodsList) {

                    ListShowTypeVo.DataBean.GoodsListBean goodsListBean = new ListShowTypeVo.DataBean.GoodsListBean();

                    goodsListBean.setId(orderGoods.getId());
                    goodsListBean.setGoodsName(orderGoods.getGoodsName());
                    goodsListBean.setPicUrl(orderGoods.getPicUrl());
                    goodsListBean.setNumber(orderGoods.getNumber());
                    goodsListBeans.add(goodsListBean);
                    dataBean.setGoodsList(goodsListBeans);

                    dataBeans.add(dataBean);

                }

            }
            listShowTypeVo.setData(dataBeans);
            return listShowTypeVo;
        }


        if (showType == 2) {
            orderExample.createCriteria().andOrderStatusEqualTo((short) 201);
            long count = orderMapper.countByExample(orderExample);
            listShowTypeVo.setCount((int) count);
            int ceil = (int) Math.ceil(count / size);
            if (ceil > 0) {
                page = size + 1;
            } else {
                page = 0;
            }
            listShowTypeVo.setTotalPages(page);
            List<Order> orders = orderMapper.selectByExample(orderExample);


            for (Order order : orders) {


                ListShowTypeVo.DataBean dataBean = new ListShowTypeVo.DataBean();

                if (order.getOrderStatus() == 201) {
                    dataBean.setOrderStatusText("已付款");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(true);
                    dataBean.setHandleOption(handleOptionBean);

                }
                Integer orderId = order.getId();
                OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
                orderGoodsExample.createCriteria().andOrderIdEqualTo(orderId);
                List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);

                ArrayList<ListShowTypeVo.DataBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (OrderGoods orderGoods : orderGoodsList) {

                    ListShowTypeVo.DataBean.GoodsListBean goodsListBean = new ListShowTypeVo.DataBean.GoodsListBean();

                    goodsListBean.setId(orderGoods.getId());
                    goodsListBean.setGoodsName(orderGoods.getGoodsName());
                    goodsListBean.setPicUrl(orderGoods.getPicUrl());
                    goodsListBean.setNumber(orderGoods.getNumber());
                    goodsListBeans.add(goodsListBean);
                    dataBean.setGoodsList(goodsListBeans);

                    dataBeans.add(dataBean);

                }

            }
            listShowTypeVo.setData(dataBeans);
            return listShowTypeVo;

        }


        if (showType == 3) {
            orderExample.createCriteria().andOrderStatusEqualTo((short) 301);
            long all = orderMapper.countByExample(orderExample);

//            long l = orderMapper.countByStatus(101);
//            long count = orderMapper.countByExample(orderExample);
            listShowTypeVo.setCount((int) all);
            listShowTypeVo.setTotalPages((int) Math.ceil(all / size));
            List<Order> orders = orderMapper.selectByExample(orderExample);


            for (Order order : orders) {

                ListShowTypeVo.DataBean dataBean = new ListShowTypeVo.DataBean();

                if (order.getOrderStatus() == 301) {
                    dataBean.setOrderStatusText("已发货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(false);
                    handleOptionBean.setConfirm(true);
                    handleOptionBean.setDelete(false);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(false);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);


                }
                Integer orderId = order.getId();
                OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
                orderGoodsExample.createCriteria().andOrderIdEqualTo(orderId);
                List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);

                ArrayList<ListShowTypeVo.DataBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (OrderGoods orderGoods : orderGoodsList) {

                    ListShowTypeVo.DataBean.GoodsListBean goodsListBean = new ListShowTypeVo.DataBean.GoodsListBean();

                    goodsListBean.setId(orderGoods.getId());
                    goodsListBean.setGoodsName(orderGoods.getGoodsName());
                    goodsListBean.setPicUrl(orderGoods.getPicUrl());
                    goodsListBean.setNumber(orderGoods.getNumber());
                    goodsListBeans.add(goodsListBean);
                    dataBean.setGoodsList(goodsListBeans);

                    dataBeans.add(dataBean);

                }

            }
            listShowTypeVo.setData(dataBeans);
            return listShowTypeVo;

        }
        if (showType == 4) {
            orderExample.createCriteria().andOrderStatusEqualTo((short) 401);
            long all = orderMapper.countByExample(orderExample);

//            long l = orderMapper.countByStatus(101);
//            long count = orderMapper.countByExample(orderExample);
            listShowTypeVo.setCount((int) all);
            listShowTypeVo.setTotalPages((int) Math.ceil(all / size));
            List<Order> orders = orderMapper.selectByExample(orderExample);

            for (Order order : orders) {
                ListShowTypeVo.DataBean dataBean = new ListShowTypeVo.DataBean();
                if (order.getOrderStatus() == 401) {
                    dataBean.setOrderStatusText("用户收货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(true);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(true);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);

                } else if (order.getOrderStatus() == 402) {
                    dataBean.setOrderStatusText("系统收货");
                    dataBean.setIsGroupin(false);
                    dataBean.setOrderSn(order.getOrderSn());
                    dataBean.setActualPrice(order.getActualPrice());
                    dataBean.setId(order.getId());
                    handleOptionBean.setCancel(false);
                    handleOptionBean.setComment(true);
                    handleOptionBean.setConfirm(false);
                    handleOptionBean.setDelete(true);
                    handleOptionBean.setPay(false);
                    handleOptionBean.setRebuy(true);
                    handleOptionBean.setRefund(false);
                    dataBean.setHandleOption(handleOptionBean);

                }
                Integer orderId = order.getId();
                OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
                orderGoodsExample.createCriteria().andOrderIdEqualTo(orderId);
                List<OrderGoods> orderGoodsList = orderGoodsMapper.selectByExample(orderGoodsExample);

                ArrayList<ListShowTypeVo.DataBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (OrderGoods orderGoods : orderGoodsList) {

                    ListShowTypeVo.DataBean.GoodsListBean goodsListBean = new ListShowTypeVo.DataBean.GoodsListBean();

                    goodsListBean.setId(orderGoods.getId());
                    goodsListBean.setGoodsName(orderGoods.getGoodsName());
                    goodsListBean.setPicUrl(orderGoods.getPicUrl());
                    goodsListBean.setNumber(orderGoods.getNumber());
                    goodsListBeans.add(goodsListBean);
                    dataBean.setGoodsList(goodsListBeans);

                    dataBeans.add(dataBean);

                }

            }
        }
        listShowTypeVo.setData(dataBeans);
        return listShowTypeVo;
    }


    @Override
    public void refund(Integer orderId) {
        Order order = orderMapper.selectByPrimaryKey(orderId);
        order.setOrderStatus((short) 203);
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public void confirm(Integer orderId) {
        Order order = orderMapper.selectByPrimaryKey(orderId);
        order.setOrderStatus((short) 401);
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public OrderGoods goods(Integer orderId, Integer goodsId) {

        Integer integer = orderGoodsMapper.selectorderIdBygoodsId(goodsId);
        OrderGoods orderGoods = orderGoodsMapper.selectByPrimaryKey(integer);

        return orderGoods;
    }
}

